//! YesPlayLove.debug.js
//

(function() {

Type.registerNamespace('Yoshi.Classes');

////////////////////////////////////////////////////////////////////////////////
// EmotionalScale

EmotionalScale = function EmotionalScale() {
    EmotionalScale.initializeBase(this);
    this.element = $("<div class='EmotionalScale'/>");
    var ls = $('<ol/>').appendTo(this.element);
    var $enum1 = ss.IEnumerator.getEnumerator(Items.emotionalScale);
    while ($enum1.moveNext()) {
        var s = $enum1.current;
        $('<li/>').appendTo(ls).html(s);
    }
}


Type.registerNamespace('YesPlayLove.Classes');

////////////////////////////////////////////////////////////////////////////////
// AlivenessFeed

AlivenessFeed = function AlivenessFeed() {
    /// <field name="currentFeed" type="FeedBubble" static="true">
    /// </field>
}
AlivenessFeed.deleteFeedItem = function AlivenessFeed$deleteFeedItem(itemId) {
    /// <param name="itemId" type="String">
    /// </param>
    if (AlivenessFeed.currentFeed != null) {
        Master.profile.feedData.deleteItem(itemId);
        AlivenessFeed.updateFeedAw(Await.get_asyncAw());
    }
}
AlivenessFeed.updateFeedAw = function AlivenessFeed$updateFeedAw(awp) {
    /// <param name="awp" type="Await">
    /// </param>
    new Await().addDx(function() {
        if (AlivenessFeed.currentFeed != null) {
            AlivenessFeed.currentFeed.refresh();
        }
    }).commit(awp);
}


////////////////////////////////////////////////////////////////////////////////
// EmailData

EmailData = function EmailData() {
    /// <field name="sentRx" type="String" static="true">
    /// </field>
    /// <field name="rcvdRx" type="String" static="true">
    /// </field>
    /// <field name="_partitionKeyLists$3" type="String" static="true">
    /// </field>
    /// <field name="_partitionKeyConvs$3" type="String" static="true">
    /// </field>
    /// <field name="_rowKeyRcvd$3" type="String">
    /// </field>
    /// <field name="_rowKeySent$3" type="String">
    /// </field>
    EmailData.initializeBase(this);
    this._rowKeySent$3 = this.get_my().id;
    this._rowKeyRcvd$3 = this.get_my().id;
}
EmailData.prototype = {
    _rowKeyRcvd$3: null,
    _rowKeySent$3: null,
    
    get_my: function EmailData$get_my() {
        /// <value type="YoshiUser"></value>
        return Master.profile.get_my();
    },
    
    getMailListAw: function EmailData$getMailListAw(awp, uid) {
        /// <param name="awp" type="Await">
        /// </param>
        /// <param name="uid" type="String">
        /// </param>
        uid = (uid || this.get_my().id);
        new Await().addAw(FileBlobBase.retrieveBlobStringAw, 'db/email/lists', uid).handleDl(Exceptions.blobLoadError, Await.rethrowAw).addDx(function(aw) {
            awp.set_item(PkgBase.resultRx, (aw.get_item(PkgBase.resultRx) != null) ? JSON.parse('[' + FileBlobBase.cleanListData(aw.get_item(PkgBase.resultRx)) + ']') : null);
        }).commit(awp);
    },
    
    sendMailAw: function EmailData$sendMailAw(awp, toId, msg) {
        /// <param name="awp" type="Await">
        /// </param>
        /// <param name="toId" type="String">
        /// </param>
        /// <param name="msg" type="String">
        /// </param>
        new Await().addAw(ProfileData.getUserByIdAw, toId).addDx(ss.Delegate.create(this, function() {
            var toUser = ProfileData.getUserFromCacheById(toId);
            ss.Debug.assert(toId != null, 'toId != null');
            var em = new EmailItem();
            em.id = Formulas.get_newId();
            em.fromId = this.get_my().id;
            em.toId = toId;
            em.message = msg;
            em.alias = this.get_my().alias;
            em.unread = true;
            em.createTime = new Date().getTime();
            var rowKey = this.get_my().id + 'e' + toId;
            FileBlobBase.appendBlobStringAw(Await.get_asyncAw(), 'db/email/convs', rowKey, PkgBase.resultRx, JSON.stringify(em));
            rowKey = toId + 'e' + this.get_my().id;
            FileBlobBase.appendBlobStringAw(Await.get_asyncAw(), 'db/email/convs', rowKey, PkgBase.resultRx, JSON.stringify(em));
            var el = new EmailListItem();
            el.peek = msg.substring(0, 60);
            new Await().addAw(ss.Delegate.create(this, this.updateStorageListsAw), this.get_my().id, toId, el).commit(awp);
            if (toUser.emmMessage) {
                var mail = { to: toUser.email, from: this.get_my().email, subject: String.format(EmailTheme.mailSubject, toUser.alias), content: msg };
                new Await().addAw(CloudMail.sendMailAw, mail).commit();
            }
        })).commit();
    },
    
    updateStorageListsAw: function EmailData$updateStorageListsAw(awp, id1, id2, emListItem) {
        /// <param name="awp" type="Await">
        /// </param>
        /// <param name="id1" type="String">
        /// </param>
        /// <param name="id2" type="String">
        /// </param>
        /// <param name="emListItem" type="Object">
        /// </param>
        var em1 = $.extend(new EmailListItem(), emListItem);
        var em2 = $.extend(new EmailListItem(), emListItem);
        new Await().addAw(ProfileData.getUserByIdAw, id2).addDx(ss.Delegate.create(this, function() {
            var usr = ProfileData.getUserFromCacheById(id2);
            em1.fromId = usr.id;
            em1.lastId = this.get_my().id;
            em1.fAlias = usr.alias;
            em1.lAlias = this.get_my().alias;
            em2.fromId = this.get_my().id;
            em2.lastId = this.get_my().id;
            em2.fAlias = this.get_my().alias;
            em2.lAlias = this.get_my().alias;
        })).addAw(ss.Delegate.create(this, this.updateListAw), id1, em1).addAw(ss.Delegate.create(this, this.updateListAw), id2, em2).commit(awp);
    },
    
    updateListAw: function EmailData$updateListAw(awp, id1, emListItem) {
        /// <param name="awp" type="Await">
        /// </param>
        /// <param name="id1" type="String">
        /// </param>
        /// <param name="emListItem" type="Object">
        /// </param>
        var el = emListItem;
        new Await().addAw(ss.Delegate.create(this, this.getMailListAw), id1).handleDl(Exceptions.blobLoadError, Await.ignoreAw).addDl(function(aw) {
            var list;
            if (ss.isValue(aw.get_item(PkgBase.resultRx))) {
                list = aw.get_item(PkgBase.resultRx);
            }
            else {
                list = [];
            }
            var found = false;
            var $enum1 = ss.IEnumerator.getEnumerator(list);
            while ($enum1.moveNext()) {
                var item = $enum1.current;
                if (item.fromId === el.fromId) {
                    found = true;
                    if (el.unread) {
                        item.peek = el.peek;
                        item.lastId = el.lastId;
                        item.lAlias = el.lAlias;
                    }
                    item.unread = el.unread;
                    item.modifyTime = new Date().getTime();
                    FileBlobBase.forceStoreBlob('db/email/lists', id1);
                    FileBlobBase.storeBlobStringAw(aw, { partitionKey: 'db/email/lists', rowKey: id1, content: FileBlobBase.simpleList(list) });
                    break;
                }
            }
            if (!found) {
                FileBlobBase.appendBlobStringAw(aw, 'db/email/lists', id1, PkgBase.resultRx, JSON.stringify(el));
            }
        }).commit(awp);
    },
    
    getConvAw: function EmailData$getConvAw(awp, fromId) {
        /// <param name="awp" type="Await">
        /// </param>
        /// <param name="fromId" type="String">
        /// </param>
        var rowKey = this.get_my().id + 'e' + fromId;
        new Await().addAw(FileBlobBase.retrieveBlobStringAw, 'db/email/convs', rowKey).handleDl(Exceptions.blobLoadError, Await.abortAw).addDx(function(aw) {
            awp.set_item(PkgBase.resultRx, (aw.get_item(PkgBase.resultRx) != null) ? JSON.parse('[' + FileBlobBase.cleanListData(aw.get_item(PkgBase.resultRx)) + ']') : null);
        }).commit(awp);
    }
}


////////////////////////////////////////////////////////////////////////////////
// YoshiFlow

YoshiFlow = function YoshiFlow() {
    YoshiFlow.initializeBase(this);
}
YoshiFlow.prototype = {
    
    playAliasAw: function YoshiFlow$playAliasAw(awp, options) {
        /// <param name="awp" type="Await">
        /// </param>
        /// <param name="options" type="Object">
        /// </param>
        this.playAlias(options).appendTo(this.pageCluster);
        awp.done();
    },
    
    multipleChoiceAw: function YoshiFlow$multipleChoiceAw(awp, question) {
        /// <param name="awp" type="Await">
        /// </param>
        /// <param name="question" type="Object">
        /// </param>
        var name = question['name'] || Formulas.get_newId();
        this.multipleChoice(name, question).appendTo(this.pageCluster);
        awp.done();
    },
    
    animateInAw: function YoshiFlow$animateInAw(awp, name) {
        /// <param name="awp" type="Await">
        /// </param>
        /// <param name="name" type="String">
        /// </param>
        new Await().addAw(ss.Delegate.create(this, this.slideInByNameAw), name).commit(awp);
    },
    
    redrawAw: function YoshiFlow$redrawAw(awp, tu) {
        /// <param name="awp" type="Await">
        /// </param>
        /// <param name="tu" type="Nsb.Classes.Truple">
        /// </param>
        tu.element.find('dt').each(ss.Delegate.create(this, function(i, domEl) {
            var ths = $(domEl);
            ths.html(this.redraw(ths.html()));
            return true;
        }));
    },
    
    redraw: function YoshiFlow$redraw(txt) {
        /// <param name="txt" type="String">
        /// </param>
        /// <returns type="String"></returns>
        txt = txt.replaceAll('%alias%', Strings.paraCase(Master.profile.get_myAlias()));
        return txt;
    }
}


////////////////////////////////////////////////////////////////////////////////
// YoshiPage

YoshiPage = function YoshiPage() {
    /// <field name="pageMaster" type="jQueryObject">
    /// </field>
    /// <field name="pageFooter" type="jQueryObject">
    /// </field>
    /// <field name="pageCluster" type="jQueryObject">
    /// </field>
    /// <field name="_focusElement$5" type="jQueryObject">
    /// </field>
    /// <field name="topBar" type="TopBar">
    /// </field>
    YoshiPage.initializeBase(this);
    this.set_title('Yoshi Page');
    this.pageMaster = $('#' + Master.pageMasterId);
    Inform.log('Creating page instance FullName={0}', Type.getInstanceType(this).get_fullName());
}
YoshiPage.prototype = {
    pageMaster: null,
    pageFooter: null,
    pageCluster: null,
    _focusElement$5: null,
    topBar: null,
    
    get_title: function YoshiPage$get_title() {
        /// <value type="String"></value>
        return document.title;
    },
    set_title: function YoshiPage$set_title(value) {
        /// <value type="String"></value>
        document.title = value;
        return value;
    },
    
    updatePage: function YoshiPage$updatePage(pu) {
        /// <param name="pu" type="PageUpdate">
        /// </param>
        if (this.topBar != null) {
            this.topBar.updatePage(pu);
        }
    },
    
    focusEvent: function YoshiPage$focusEvent(e) {
        /// <param name="e" type="jQueryEvent">
        /// </param>
        this._focusElement$5 = (ss.isValue(e)) ? $(e.target) : null;
    },
    
    isFocused: function YoshiPage$isFocused(el) {
        /// <param name="el" type="jQueryObject">
        /// </param>
        /// <returns type="Boolean"></returns>
        return this._focusElement$5 != null && el[0] === this._focusElement$5[0];
    },
    
    publicBuildAw: function YoshiPage$publicBuildAw(awp, pageTitle) {
        /// <param name="awp" type="Await">
        /// </param>
        /// <param name="pageTitle" type="String">
        /// </param>
        var centerBox = $("<div id='PageCenter'/>").appendTo(this.pageMaster);
        this.element = $("<div id='PageContent'/>").appendTo(centerBox).addClass(Type.getInstanceType(this).get_name());
        this.set_title(pageTitle);
        new Await().addFn(ss.Delegate.create(this, this.basicPage)).addFn(ss.Delegate.create(this, this.basicCluster)).addFn(ss.Delegate.create(this, this.basicFooter)).addAw(ss.Delegate.create(this, this.refreshAw)).addDx(function() {
            FileBlobBase.svCnt--;
        }).commit(awp);
    },
    
    basicBuildAw: function YoshiPage$basicBuildAw(awp, pageTitle) {
        /// <param name="awp" type="Await">
        /// </param>
        /// <param name="pageTitle" type="String">
        /// </param>
        Inform.debug('BasicBuildAw');
        var centerBox = $("<div id='PageCenter'/>").appendTo(this.pageMaster);
        this.element = $("<div id='PageContent'/>").appendTo(centerBox).addClass(Type.getInstanceType(this).get_name());
        this.set_title(pageTitle);
        new Await().addFn(ss.Delegate.create(this, this.createTopBar)).addFn(ss.Delegate.create(this, this.basicPage)).addAw(ss.Delegate.create(Master.fbData, Master.fbData.authenticateAw)).addAw(ProfileData.loadMyProfileAw).handleDl(Exceptions.newUser, function() {
            Master.GoPage(AllPages.newUserPage);
        }).addFn(ss.Delegate.create(this, this.showTopUser)).addFn(ss.Delegate.create(this, this.basicCluster)).addFn(ss.Delegate.create(this, this.basicFooter)).addAw(ss.Delegate.create(this, this.refreshAw)).addDx(function() {
            FileBlobBase.svCnt--;
        }).commit(awp);
    },
    
    refreshAw: function YoshiPage$refreshAw(awp) {
        /// <param name="awp" type="Await">
        /// </param>
        awp.done();
    },
    
    basicPage: function YoshiPage$basicPage() {
        var topic = $("<h1 id='Topic'/>").html(ThemeBase.siteTitle).appendTo(this.element);
        var yoshi = new Actor().fromHtml("<img id='TopicImage'/>");
        yoshi.element.appendTo(topic).attr('src', MagneticListPageTheme.logoImage).mouseenter(function() {
            yoshi.shake();
        });
    },
    
    basicCluster: function YoshiPage$basicCluster() {
        $("<div id='PageGigs' class='FrontContent'/>").appendTo(this.element);
        this.pageCluster = $("<div class='PageCluster'/>").appendTo(this.element);
    },
    
    basicFooter: function YoshiPage$basicFooter() {
        this.pageFooter = $("<div class='PageFooter'/>").appendTo(this.element).html('');
    },
    
    destroy: function YoshiPage$destroy() {
    },
    
    createTopBar: function YoshiPage$createTopBar() {
        this.topBar = new TopBar(this.element, { links: true });
    },
    
    showTopUser: function YoshiPage$showTopUser() {
        if (this.topBar != null) {
            this.topBar.showUser();
        }
    },
    
    loadPageCssAw: function YoshiPage$loadPageCssAw(awp) {
        /// <param name="awp" type="Await">
        /// </param>
        new Await().loadCss('Scripts/Css/' + Type.getInstanceType(this).get_name() + '.css').commit(awp);
    },
    
    loadNamespaceCssAw: function YoshiPage$loadNamespaceCssAw(awp) {
        /// <param name="awp" type="Await">
        /// </param>
        new Await().loadCss('Scripts/Css/' + Type.getInstanceType(this).get_fullName().split('.')[0] + '.css').commit(awp);
    }
}


Type.registerNamespace('YesPlayLove.Clusters');

////////////////////////////////////////////////////////////////////////////////
// AlivenessBubble

AlivenessBubble = function AlivenessBubble(appendEl, item) {
    /// <param name="appendEl" type="jQueryObject">
    /// </param>
    /// <param name="item" type="FeedItem">
    /// </param>
    /// <field name="_item$3" type="FeedItem">
    /// </field>
    /// <field name="_liveEventsAdded$3" type="Boolean">
    /// </field>
    /// <field name="_text$3" type="jQueryObject">
    /// </field>
    this._liveEventsAdded$3 = AlivenessBubble._addLiveEvents$3();
    AlivenessBubble.initializeBase(this);
    this._item$3 = item;
    this.element = $("<div class='AlivenessBubble'/>").data('itemId', item.id);
    this._text$3 = $('<p/>').appendTo(this.element).html("<span class='Quote'>&hearts; &ldquo;</span>" + item.message + "<span class='Quote'>&rdquo;</span>").data('msg', item.message);
    $("<div class='ActionBtn LikeBtn'/>").appendTo(this._text$3).html(ThemeBase.smile).attr('title', ThemeBase.likeBtnTitle).click(ss.Delegate.create(this, this.addLike));
    $("<div class='ActionBtn CommentBtn'/>").appendTo(this._text$3).html(ThemeBase.clubs).attr('title', ThemeBase.commentBtnTitle).click(ss.Delegate.create(this, this.makeComment));
    $("<div class='ActionBtn StreamBtn'/>").appendTo(this._text$3).html(ThemeBase.hearts).attr('title', ThemeBase.streamBtnTitle).click(ss.Delegate.create(this, this.addToStream));
    $("<div class='ActionBtn EditBtn'/>").appendTo(this._text$3).html(ThemeBase.diamonds).attr('title', ThemeBase.editBtnTitle).click(ss.Delegate.create(this, this.editComment));
    this.element.appendTo(appendEl);
    if (item.hasComments) {
        new Await().addAw(CommentData.newGetAw, item.id).handleDl(Exceptions.blobLoadError, Await.abortAw).addAw(ss.Delegate.create(this, this.attachCommentsAw)).commit();
    }
}
AlivenessBubble.nue = function AlivenessBubble$nue(el, item) {
    /// <summary>
    /// Creates an animated aliveness bubble.
    /// </summary>
    /// <param name="el" type="jQueryObject">
    /// jQueryObject where animation starts
    /// </param>
    /// <param name="item" type="FeedItem">
    /// The feed item.
    /// </param>
    /// <returns type="AlivenessBubble"></returns>
    return new AlivenessBubble(el, item);
}
AlivenessBubble.animateBubbleAw = function AlivenessBubble$animateBubbleAw(awp, msg, assocEl) {
    /// <param name="awp" type="Await">
    /// </param>
    /// <param name="msg" type="String">
    /// </param>
    /// <param name="assocEl" type="jQueryObject">
    /// </param>
    AlivenessBubble.nue($(document.body), new FeedItem(FeedItem.textCategory, msg)).animateFrom(awp, assocEl);
}
AlivenessBubble._addLiveEvents$3 = function AlivenessBubble$_addLiveEvents$3() {
    /// <returns type="Boolean"></returns>
    $('.AlivenessBubble').live('mouseenter.alivenessbubble', AlivenessBubble._showDelete$3).live('mouseleave.alivenessbubble', AlivenessBubble._hideDelete$3);
    return true;
}
AlivenessBubble._showDelete$3 = function AlivenessBubble$_showDelete$3(e) {
    /// <param name="e" type="jQueryEvent">
    /// </param>
    var el = $(e.target).closest('.AlivenessBubble');
    $("<div class='HiddenDeleteBtn'/>").appendTo(el).html('&spades;').attr('title', ThemeBase.deleteBtnTitle).click(function(e2) {
        var awx = new Await();
        if (!e2.shiftKey) {
            awx.addAw(ss.Delegate.create(new Ask(), new Ask().okCancelAw), ThemeBase.forSure).addAw(DomElement.requireResultAw, true);
        }
        awx.addDx(function() {
            DomElement.cancelEvent(e2);
            AlivenessFeed.deleteFeedItem(el.data('itemId'));
        }).commit();
    });
}
AlivenessBubble._hideDelete$3 = function AlivenessBubble$_hideDelete$3(e) {
    /// <param name="e" type="jQueryEvent">
    /// </param>
    var del = $('.HiddenDeleteBtn');
    if (del != null) {
        del.remove();
    }
}
AlivenessBubble.prototype = {
    _item$3: null,
    _text$3: null,
    
    attachCommentsAw: function AlivenessBubble$attachCommentsAw(awp) {
        /// <param name="awp" type="Await">
        /// </param>
        var comments = awp.get_item('result');
        if (comments != null) {
            var cbx = $('<div/>').insertAfter(this.element);
            var $enum1 = ss.IEnumerator.getEnumerator(comments);
            while ($enum1.moveNext()) {
                var i = $enum1.current;
                CommentBubble.insertCommentAw(Await.get_asyncAw(), cbx, i);
            }
        }
    },
    
    animateFrom: function AlivenessBubble$animateFrom(awp, hereEl) {
        /// <param name="awp" type="Await">
        /// </param>
        /// <param name="hereEl" type="jQueryObject">
        /// </param>
        /// <returns type="AlivenessBubble"></returns>
        this.element.css({ position: 'absolute', 'z-index': ThemeBase.zIndexHider + 1, top: hereEl.offset().top - 10, left: hereEl.offset().left - 10 });
        new Await().addDx(ss.Delegate.create(this, function() {
            this._text$3.css('overflow', 'hidden').css('white-space', 'nowrap');
            this.element.css('overflow', 'hidden').css('white-space', 'nowrap').css('height', this.element.height() + 'px').css('padding', '20px 40px');
            this.element.fitIntoWindow();
        })).addAw(ss.Delegate.create(this, this.animateAw), { top: -10, left: 700, width: 30, height: 20, 'padding-top': '3px', 'padding-bottom': '3px', 'padding-left': '5px', 'padding-right': '5px', 'font-size': '3pt' }, { duration: 350, easing: 'linear' }).addDx(ss.Delegate.create(this, function() {
            this.element.remove();
        })).commit(awp);
        return this;
    },
    
    addLike: function AlivenessBubble$addLike(e) {
        /// <param name="e" type="jQueryEvent">
        /// </param>
        ss.Debug.assert(ss.isValue(this._item$3), '_item has value');
        DomElement.cancelEvent(e);
        new Await().addAw(ss.Delegate.create(new Ask(), new Ask().okAw), 'Like feature comming soon ' + ThemeBase.smile).commit();
    },
    
    makeComment: function AlivenessBubble$makeComment(e) {
        /// <param name="e" type="jQueryEvent">
        /// </param>
        ss.Debug.assert(ss.isValue(this._item$3), '_item has value');
        DomElement.cancelEvent(e);
        new Await().addAw(CommentBubble.newAw, this._item$3.id, this.element).addDx(ss.Delegate.create(this, function() {
            this._item$3.hasComments = true;
        })).addAw(ss.Delegate.create(Master.profile, Master.profile.saveFeedAw)).addAw(AlivenessFeed.updateFeedAw).commit();
    },
    
    addToStream: function AlivenessBubble$addToStream(e) {
        /// <param name="e" type="jQueryEvent">
        /// </param>
        DomElement.cancelEvent(e);
        new Await().addAw(ss.Delegate.create(Master.profile, Master.profile.writeToFeedAw), FeedItem.textCategory, this._text$3.data('msg')).addAw(AlivenessFeed.updateFeedAw).addAw(AlivenessBubble.animateBubbleAw, this._text$3.data('msg'), $(e.target)).commit();
    },
    
    editComment: function AlivenessBubble$editComment(e) {
        /// <param name="e" type="jQueryEvent">
        /// </param>
        ss.Debug.assert(ss.isValue(this._item$3), '_item has value');
        DomElement.cancelEvent(e);
        new Await().addAw(AlivenessBubbleEdit.editAw, this.element, this._item$3.message).addDx(ss.Delegate.create(this, function(aw) {
            this._item$3.message = aw.get_item(PkgBase.resultRx);
        })).addAw(ss.Delegate.create(Master.profile, Master.profile.saveFeedAw)).addAw(AlivenessFeed.updateFeedAw).commit();
    }
}


////////////////////////////////////////////////////////////////////////////////
// AlivenessBubbleEdit

AlivenessBubbleEdit = function AlivenessBubbleEdit(awp, el, msg, okFace) {
    /// <param name="awp" type="Await">
    /// </param>
    /// <param name="el" type="jQueryObject">
    /// </param>
    /// <param name="msg" type="String">
    /// </param>
    /// <param name="okFace" type="String">
    /// </param>
    /// <field name="_elIn$4" type="jQueryObject">
    /// </field>
    AlivenessBubbleEdit.initializeBase(this);
    this.awpIn = awp;
    this._elIn$4 = el;
    this.msg = msg;
    this.element = $("<div class='AlivenessBubbleEdit EditBubble'/>").css({ top: el.offset().top - 10, left: el.offset().left - 10 }).bind('keydown.esc', ss.Delegate.create(this, function(e) {
        Keys.escKey(e, ss.Delegate.create(this, this.cancel));
    })).bind('keydown.shiftret', ss.Delegate.create(this, function(e) {
        Keys.shiftRetKey(e, ss.Delegate.create(this, this.ok));
    }));
    this.buildCommon();
    this.okBtn.html(okFace);
    this.cancelBtn.html(ThemeBase.cancelBtnFace);
    this.element.appendTo(document.body);
    if (okFace === ThemeBase.alivenessAddBtnFace) {
        this.okBtn.focus();
    }
    else {
        this.textarea.focus();
    }
    Cluster.hider(true);
    this.scrollInViewAw(Await.get_asyncAw(), this.element);
}
AlivenessBubbleEdit.newAw = function AlivenessBubbleEdit$newAw(awp, el, msg) {
    /// <summary>
    /// Creates an animated aliveness edit bubble.
    /// </summary>
    /// <param name="awp" type="Await">
    /// The parent await object
    /// </param>
    /// <param name="el" type="Object">
    /// jQueryObject where edit bubble pops
    /// </param>
    /// <param name="msg" type="Object">
    /// message string
    /// </param>
    new AlivenessBubbleEdit(awp, el, msg, ThemeBase.alivenessAddBtnFace);
}
AlivenessBubbleEdit.editAw = function AlivenessBubbleEdit$editAw(awp, el, msg) {
    /// <param name="awp" type="Await">
    /// </param>
    /// <param name="el" type="Object">
    /// </param>
    /// <param name="msg" type="Object">
    /// </param>
    new AlivenessBubbleEdit(awp, el, msg, ThemeBase.alivenessEditBtnFace);
}
AlivenessBubbleEdit.prototype = {
    _elIn$4: null,
    
    destroy: function AlivenessBubbleEdit$destroy() {
        new Await().addAw(ss.Delegate.create(this, this.fadeOutAw), 80).addAw(ss.Delegate.create(this, this.removeAw)).addDl(ss.Delegate.create(this, function(aw) {
            if (this.awpIn.get_item('result') != null) {
                AlivenessBubble.animateBubbleAw(aw, this.awpIn.get_item('result'), this._elIn$4);
            }
            else {
                aw.done();
            }
        })).addFn(Cluster.hider, false).commit(this.awpIn);
    }
}


////////////////////////////////////////////////////////////////////////////////
// CommentBubble

CommentBubble = function CommentBubble(awp, itemId, assocEl) {
    /// <param name="awp" type="Await">
    /// </param>
    /// <param name="itemId" type="String">
    /// </param>
    /// <param name="assocEl" type="jQueryObject">
    /// </param>
    /// <field name="_itemId$4" type="String">
    /// </field>
    CommentBubble.initializeBase(this);
    this._itemId$4 = itemId;
    this.awpIn = awp;
    this.element = $("<div class='CommentBubbleEdit EditBubble'/>").css({ top: assocEl.offset().top + assocEl.outerHeight(), left: assocEl.offset().left }).bind('keydown.esc', ss.Delegate.create(this, function(e) {
        Keys.escKey(e, ss.Delegate.create(this, this.cancel));
    })).bind('keydown.shiftret', ss.Delegate.create(this, function(e) {
        Keys.shiftRetKey(e, ss.Delegate.create(this, this.ok));
    }));
    this.buildCommon();
    this.okBtn.html(ThemeBase.commentAddBtnFace);
    this.cancelBtn.html(ThemeBase.cancelBtnFace);
    this.element.appendTo(document.body);
    new Await().addAw(ss.Delegate.create(this, this.scrollInViewAw), this.element).addAw(DomElement.focusElementAw, this.textarea).commit();
    Cluster.hider(true, 0.35);
}
CommentBubble.newAw = function CommentBubble$newAw(awp, itemId, assocEl) {
    /// <summary>
    /// Creates an animated comment edit bubble.
    /// </summary>
    /// <param name="awp" type="Await">
    /// The parent await object
    /// </param>
    /// <param name="itemId" type="String">
    /// The id of the item being commented on.
    /// </param>
    /// <param name="assocEl" type="jQueryObject">
    /// The element this is associated with and positioned to
    /// </param>
    new CommentBubble(awp, itemId, assocEl);
}
CommentBubble.insertCommentAw = function CommentBubble$insertCommentAw(awp, hostEl, commentItem) {
    /// <param name="awp" type="Await">
    /// </param>
    /// <param name="hostEl" type="jQueryObject">
    /// </param>
    /// <param name="commentItem" type="Object">
    /// </param>
    var item = commentItem;
    var commentBody = $("<p class='Comment'/>").appendTo(hostEl).html(item.blob);
    var usrImg = $("<img class='ByImg'/>").attr('src', ThemeBase.unknownUserPhoto).prependTo(commentBody);
    var usrName = $("<span class='ByName'/>").insertAfter(usrImg);
    new Await().addAw(ProfileData.getUserByIdAw, item.byId).handleDl(Exceptions.blobLoadError, Await.abortAw).addDx(function(aw) {
        var yu = aw.get_item(PkgBase.resultRx);
        var name = (yu.alias || yu.name);
        usrImg.attr('src', (yu.photo || ThemeBase.unknownUserPhoto));
        usrImg.attr('title', name);
        usrName.html(name).click(function() {
            new Ask().okAw(Await.get_asyncAw(), "We haven't dreamed user pages into manifestation yet!!\r\nTry again soon cause Natalie is on it " + ThemeBase.smile);
        });
        usrName.after($('<span> ' + ThemeBase.says + ' - </span>'));
    }).commit(awp);
}
CommentBubble.prototype = {
    _itemId$4: null,
    
    ok: function CommentBubble$ok(e) {
        /// <param name="e" type="jQueryEvent">
        /// </param>
        var dta = new CommentData();
        var msg = this.textarea.getFValueString();
        if (!String.isNullOrEmpty(msg)) {
            dta.writeCommentAw(Await.get_asyncAw(), this._itemId$4, msg);
        }
        CommentBubble.callBaseMethod(this, 'ok');
    }
}


////////////////////////////////////////////////////////////////////////////////
// EditBase

EditBase = function EditBase() {
    /// <field name="awpIn" type="Await">
    /// </field>
    /// <field name="cancelBtn" type="jQueryObject">
    /// </field>
    /// <field name="okBtn" type="jQueryObject">
    /// </field>
    /// <field name="textarea" type="jQueryObject">
    /// </field>
    /// <field name="msg" type="String">
    /// </field>
    EditBase.initializeBase(this);
}
EditBase.prototype = {
    awpIn: null,
    cancelBtn: null,
    okBtn: null,
    textarea: null,
    msg: '',
    
    buildCommon: function EditBase$buildCommon() {
        this.textarea = $('<textarea/>').appendTo(this.element).fValueString(this.msg);
        this.okBtn = $("<button class='Button OkBtn'/>").appendTo(this.element).click(ss.Delegate.create(this, this.ok));
        this.cancelBtn = $("<button class='Button CancelBtn'/>").appendTo(this.element).click(ss.Delegate.create(this, this.abort));
    },
    
    cancel: function EditBase$cancel(e) {
        /// <param name="e" type="jQueryEvent">
        /// </param>
        this.cancelBtn.focus().click();
    },
    
    ok: function EditBase$ok(e) {
        /// <param name="e" type="jQueryEvent">
        /// </param>
        DomElement.cancelEvent(e);
        this.awpIn.set_item(PkgBase.resultRx, this.textarea.getFValueString());
        this.destroy();
    },
    
    abort: function EditBase$abort(e) {
        /// <param name="e" type="jQueryEvent">
        /// </param>
        DomElement.cancelEvent(e);
        this.awpIn.abort();
        this.destroy();
    },
    
    destroy: function EditBase$destroy() {
        new Await().addAw(ss.Delegate.create(this, this.fadeOutAw), 80).addAw(ss.Delegate.create(this, this.removeAw)).addFn(Cluster.hider, false).commit(this.awpIn);
    }
}


////////////////////////////////////////////////////////////////////////////////
// EditListHtml

EditListHtml = function EditListHtml(awp, edEl) {
    /// <param name="awp" type="Await">
    /// </param>
    /// <param name="edEl" type="jQueryObject">
    /// </param>
    EditListHtml.initializeBase(this, [ awp, edEl ]);
}
EditListHtml.aw = function EditListHtml$aw(awp, edEl) {
    /// <param name="awp" type="Await">
    /// </param>
    /// <param name="edEl" type="jQueryObject">
    /// </param>
    new EditListHtml(awp, edEl);
}
EditListHtml.scoopData = function EditListHtml$scoopData(elToScoop) {
    /// <param name="elToScoop" type="jQueryObject">
    /// </param>
    /// <returns type="Object"></returns>
    var data = {};
    $('.SectionJar', elToScoop).each(function(i, ee) {
        var sect = {};
        data['Section' + i] = sect;
        sect['type'] = 'ol';
        sect['title'] = $(this).find('h2').getFValueString();
        var li = [];
        sect['li'] = li;
        $(this).find('li').each(function() {
            li.add($(this).getFValueString());
            return true;
        });
        return true;
    });
    return data;
}
EditListHtml.showHtmlListAw = function EditListHtml$showHtmlListAw(awp, features, appendTo) {
    /// <param name="awp" type="Await">
    /// </param>
    /// <param name="features" type="Object">
    /// </param>
    /// <param name="appendTo" type="jQueryObject">
    /// </param>
    new Await().addAw(FileBlobBase.getBlobAw, features).addDx(function(aw) {
        appendTo.addClass('Jar OuterJar');
        var data = aw.get_item(PkgBase.resultRx);
        var $dict1 = data;
        for (var $key2 in $dict1) {
            var p = { key: $key2, value: $dict1[$key2] };
            var sect = p.value;
            var sj = $("<div class='Jar SectionJar' style='position:relative'/>").appendTo(appendTo);
            $('<h2/>').html(sect['title']).appendTo(sj);
            var lj = $("<div class='Jar ListJar' style='position:relative'/>").appendTo(sj);
            var ls = $('<' + (sect['type'] || 'ul') + '/>').appendTo(lj);
            var $enum3 = ss.IEnumerator.getEnumerator(sect['li']);
            while ($enum3.moveNext()) {
                var s = $enum3.current;
                var ij = $("<div class='Jar ItemJar' style='position:relative'/>").appendTo(ls);
                $('<li/>').appendTo(ij).html(s);
            }
        }
    }).commit(awp);
}
EditListHtml.prototype = {
    
    cont: function EditListHtml$cont(e) {
        /// <param name="e" type="jQueryEvent">
        /// </param>
        new Await().addDx(ss.Delegate.create(this, function() {
            this.edEl.closest('.ItemJar').children('.SimpleAddLineBtn').first().click();
        })).commit();
    },
    
    next: function EditListHtml$next(e) {
        /// <param name="e" type="jQueryEvent">
        /// </param>
        DomElement.cancelEvent(e);
        var all = this.edEl.closest('.OuterJar').find('h2,li');
        var i = all.index(this.edEl[0]);
        var next = all.slice(i + 1).first();
        this.edEl.blur();
        new Await().addDx(function() {
            if (i >= 0 && i < (all.length - 1)) {
                next.click();
            }
            else {
                all.first().click();
            }
        }).commit();
    },
    
    prior: function EditListHtml$prior(e) {
        /// <param name="e" type="jQueryEvent">
        /// </param>
        DomElement.cancelEvent(e);
        var all = this.edEl.closest('.OuterJar').find('h2,li');
        var i = all.index(this.edEl[0]);
        var next = all.slice(i - 1).first();
        this.edEl.blur();
        new Await().addDx(function() {
            if (i > 0) {
                next.click();
            }
            else {
                all.last().click();
            }
        }).commit();
    }
}


////////////////////////////////////////////////////////////////////////////////
// EmailBase

EmailBase = function EmailBase(cluster) {
    /// <param name="cluster" type="EmailCluster">
    /// </param>
    /// <field name="_active" type="Boolean">
    /// </field>
    /// <field name="_emailBubbles" type="EmailBubbles">
    /// </field>
    /// <field name="_emailCluster" type="EmailCluster">
    /// </field>
    /// <field name="_emailInbox" type="EmailInbox">
    /// </field>
    /// <field name="_emailProfile" type="YesPlayLove.Clusters.EmailProfile">
    /// </field>
    /// <field name="data" type="EmailData" static="true">
    /// </field>
    /// <field name="wrapper" type="jQueryObject">
    /// </field>
    EmailBase.initializeBase(this);
    if (EmailBase.data == null) {
        EmailBase.data = new EmailData();
    }
    this._emailCluster = cluster;
}
EmailBase.prototype = {
    _active: false,
    _emailBubbles: null,
    _emailCluster: null,
    _emailInbox: null,
    _emailProfile: null,
    wrapper: null,
    
    initialize: function EmailBase$initialize(active) {
        /// <param name="active" type="Boolean">
        /// </param>
        this._active = active;
        ss.Debug.assert(this.element != null, 'Element != null');
        this.element.empty();
    },
    
    focusInput: function EmailBase$focusInput() {
        /// <returns type="EmailBase"></returns>
        return this;
    },
    
    baseRebuild: function EmailBase$baseRebuild(active) {
        /// <param name="active" type="Boolean">
        /// </param>
        new Await().addAw(ss.Delegate.create(this, this.fadeOutAw), ThemeBase.fadeOut).addDx(ss.Delegate.create(this, function() {
            this.build(active);
        })).addAw(ss.Delegate.create(this, this.fadeInAw), ThemeBase.fadeIn).commit();
    },
    
    scrollInActiveAsync: function EmailBase$scrollInActiveAsync() {
        if (this._active) {
            new Await().addAw(ss.Delegate.create(this, this.scrollInViewAw), this.element).commit();
        }
    },
    
    _hookupCluster: function EmailBase$_hookupCluster(cluster) {
        /// <param name="cluster" type="EmailCluster">
        /// </param>
        /// <returns type="EmailBase"></returns>
        ss.Debug.assert(cluster != null, 'cluster != null');
        this._emailInbox = cluster._emailInbox;
        this._emailProfile = cluster._emailProfile;
        this._emailBubbles = cluster._emailBubbles;
        return this;
    },
    
    _hookupAll: function EmailBase$_hookupAll(cluster) {
        /// <param name="cluster" type="EmailCluster">
        /// </param>
        /// <returns type="EmailBase"></returns>
        this._emailInbox._hookupCluster(cluster);
        this._emailProfile._hookupCluster(cluster);
        this._emailBubbles._hookupCluster(cluster);
        return this;
    }
}


////////////////////////////////////////////////////////////////////////////////
// EmailBubbles

EmailBubbles = function EmailBubbles(cluster) {
    /// <param name="cluster" type="EmailCluster">
    /// </param>
    /// <field name="_emailMessage" type="EmailMessage">
    /// </field>
    /// <field name="_emailReply" type="EmailReply">
    /// </field>
    EmailBubbles.initializeBase(this, [ cluster ]);
}
EmailBubbles.prototype = {
    _emailMessage: null,
    _emailReply: null,
    
    build: function EmailBubbles$build(active) {
        /// <param name="active" type="Boolean">
        /// </param>
        /// <returns type="EmailBase"></returns>
        this.initialize(active);
        this.element.empty();
        return this;
    },
    
    appendSend: function EmailBubbles$appendSend(active) {
        /// <param name="active" type="Boolean">
        /// </param>
        /// <returns type="EmailMessage"></returns>
        this._emailMessage = new EmailMessage(this._emailCluster).fromHtml('<div/>');
        this._emailMessage._hookupCluster(this._emailCluster).build(active).element.appendTo(this.element).fadeIn(ThemeBase.fadeIn);
        return this._emailMessage;
    },
    
    appendReply: function EmailBubbles$appendReply(active) {
        /// <param name="active" type="Boolean">
        /// </param>
        /// <returns type="EmailReply"></returns>
        this._emailReply = new EmailReply(this._emailCluster).fromHtml('<div/>');
        this._emailReply._hookupCluster(this._emailCluster).build(active).element.appendTo(this.element).fadeIn(ThemeBase.fadeIn);
        return this._emailReply;
    },
    
    fill: function EmailBubbles$fill(item) {
        /// <param name="item" type="Object">
        /// </param>
        /// <returns type="EmailBase"></returns>
        throw Exceptions.notImplementedException();
    },
    
    rebuild: function EmailBubbles$rebuild(active) {
        /// <param name="active" type="Boolean">
        /// </param>
        /// <returns type="EmailBubbles"></returns>
        this.baseRebuild(active);
        return this;
    },
    
    rebuildMessage: function EmailBubbles$rebuildMessage(active) {
        /// <param name="active" type="Boolean">
        /// </param>
        /// <returns type="EmailBubbles"></returns>
        if (this._emailMessage != null && this._emailMessage._active !== active) {
            new Await().addAw(ss.Delegate.create(this._emailMessage, this._emailMessage.rebuildAw), active).commit();
        }
        return this;
    },
    
    clear: function EmailBubbles$clear() {
        this.element.empty();
        this._emailMessage = null;
        this._emailReply = null;
    },
    
    scrollActiveToView: function EmailBubbles$scrollActiveToView() {
        if (this._emailReply != null && this._emailReply._active) {
            this._emailReply.scrollInActiveAsync();
        }
        else if (this._emailMessage != null && this._emailMessage._active) {
            this._emailMessage.scrollInActiveAsync();
        }
    },
    
    showBubbles: function EmailBubbles$showBubbles(fromId) {
        /// <param name="fromId" type="String">
        /// </param>
        new Await().addFn(ss.Delegate.create(this, this.clear)).addAw(ss.Delegate.create(EmailBase.data, EmailBase.data.getConvAw), fromId).handleDl(Exceptions.blobLoadError, Await.abortAw).addDx(ss.Delegate.create(this, function(aw) {
            var myId = EmailBase.data.get_my().id;
            var cx = aw.get_item(PkgBase.resultRx);
            var cnt = 0;
            var lastIsOther = false;
            var $enum1 = ss.IEnumerator.getEnumerator(cx);
            while ($enum1.moveNext()) {
                var i = $enum1.current;
                var atEnd = ++cnt === cx.length;
                if (i.toId === myId && i.fromId === fromId) {
                    this.appendSend(atEnd).fill(i.message);
                    if (atEnd) {
                        lastIsOther = true;
                    }
                }
                else {
                    this.appendReply(false).fill(i.message);
                }
            }
            if (!lastIsOther) {
                this.appendReply(true).fill('').focusInput();
            }
            if (this._emailMessage != null) {
                this._emailMessage.scrollInActiveAsync();
            }
            if (this._emailReply != null) {
                this._emailReply.scrollInActiveAsync();
            }
        })).commit();
    }
}


////////////////////////////////////////////////////////////////////////////////
// EmailCluster

EmailCluster = function EmailCluster(cluster) {
    /// <param name="cluster" type="EmailCluster">
    /// </param>
    /// <field name="_monitorInterval$5" type="Number" integer="true" static="true">
    /// </field>
    /// <field name="_timer$5" type="Number" integer="true" static="true">
    /// </field>
    /// <field name="monitorInbox" type="Boolean" static="true">
    /// </field>
    EmailCluster.initializeBase(this, [ cluster ]);
    this._emailCluster = this;
}
EmailCluster.prototype = {
    
    build: function EmailCluster$build(active) {
        /// <param name="active" type="Boolean">
        /// </param>
        /// <returns type="EmailBase"></returns>
        this.element = $("<div class='EmailBubble Composite'/>");
        this.initialize(active);
        this._emailInbox = new EmailInbox(this).fromHtml("<div class='Inbox'/>");
        this._emailProfile = new YesPlayLove.Clusters.EmailProfile(this).fromHtml("<div class='Profile'/>");
        this._emailBubbles = new EmailBubbles(this).fromHtml("<div class='Bubbles'/>");
        this._hookupAll(this);
        this._emailInbox.build(true).element.appendTo(this.element);
        this._emailProfile.build(true).element.appendTo(this.element);
        this._emailBubbles.build(true).element.appendTo(this.element);
        new Await().addAw(ss.Delegate.create(this._emailInbox, this._emailInbox.refreshAw)).addDx(ss.Delegate.create(this, function() {
            window.clearInterval(EmailCluster._timer$5);
            EmailCluster._timer$5 = window.setInterval(ss.Delegate.create(this, this._monitorLoop$5), 5000);
            this._monitorLoop$5();
        })).commit();
        return this;
    },
    
    fill: function EmailCluster$fill(item) {
        /// <param name="item" type="Object">
        /// </param>
        /// <returns type="EmailBase"></returns>
        throw Exceptions.notImplementedException();
    },
    
    destroy: function EmailCluster$destroy() {
        window.clearInterval(EmailCluster._timer$5);
        EmailCluster._timer$5 = 0;
    },
    
    _monitorLoop$5: function EmailCluster$_monitorLoop$5() {
        Inform.trace('{0}.MonitorLoop', Type.getInstanceType(this).get_name());
        if (EmailCluster.monitorInbox) {
            this._emailInbox.refreshAw(Await.get_asyncAw());
        }
    }
}


////////////////////////////////////////////////////////////////////////////////
// EmailInbox

EmailInbox = function EmailInbox(cluster) {
    /// <param name="cluster" type="EmailCluster">
    /// </param>
    /// <field name="_inboxList$5" type="jQueryObject">
    /// </field>
    /// <field name="_emptyNote$5" type="jQueryObject">
    /// </field>
    EmailInbox.initializeBase(this, [ cluster ]);
}
EmailInbox.sorter = function EmailInbox$sorter(a, b) {
    /// <param name="a" type="EmailListItem">
    /// </param>
    /// <param name="b" type="EmailListItem">
    /// </param>
    /// <returns type="Number" integer="true"></returns>
    if (a.unread !== b.unread) {
        return (a.unread) ? -1 : 1;
    }
    return b.modifyTime - a.modifyTime;
}
EmailInbox.prototype = {
    _inboxList$5: null,
    _emptyNote$5: null,
    
    build: function EmailInbox$build(active) {
        /// <param name="active" type="Boolean">
        /// </param>
        /// <returns type="EmailBase"></returns>
        this.initialize(active);
        this.element.addClass('Section');
        $("<div class='Header'/>").appendTo(this.element).html(EmailTheme.inboxTitle);
        this._emptyNote$5 = $("<div class='InboxEmpty Hidden'/>").appendTo(this.element).html(EmailTheme.noConv);
        this._inboxList$5 = $("<ul class='InboxList'/>").appendTo(this.element);
        return this;
    },
    
    fill: function EmailInbox$fill(item) {
        /// <param name="item" type="Object">
        /// </param>
        /// <returns type="EmailBase"></returns>
        throw Exceptions.notImplementedException();
    },
    
    refreshAw: function EmailInbox$refreshAw(awp) {
        /// <param name="awp" type="Await">
        /// </param>
        new Await().addAw(ss.Delegate.create(EmailBase.data, EmailBase.data.getMailListAw)).handleDl(Exceptions.blobLoadError, Await.ignoreAw).addDx(ss.Delegate.create(this, function(aw) {
            this.updateList(aw.get_item(PkgBase.resultRx));
        })).commit(awp);
    },
    
    updateList: function EmailInbox$updateList(list) {
        /// <param name="list" type="Array">
        /// </param>
        this._inboxList$5.empty();
        if (list == null) {
            this._emptyNote$5.removeClass('Hidden');
            return;
        }
        this._emptyNote$5.addClass('Hidden');
        list = $.extend([], list);
        list.sort(EmailInbox.sorter);
        var $enum1 = ss.IEnumerator.getEnumerator(list);
        while ($enum1.moveNext()) {
            var item = $enum1.current;
            this._createItem$5(item).appendTo(this._inboxList$5);
        }
    },
    
    _createItem$5: function EmailInbox$_createItem$5(item) {
        /// <param name="item" type="EmailListItem">
        /// </param>
        /// <returns type="jQueryObject"></returns>
        var line = $('<li/>');
        $("<span class='Alias'/>").appendTo(line).html(item.fAlias).attr('title', item.fAlias);
        var msg = (item.peek.length > 54) ? item.peek.substr(0, 50) + ' ...' : item.peek;
        $("<span class='Message'/>").appendTo(line).html(item.lAlias + ' says - ' + msg);
        if (item.unread) {
            line.addClass('Unread');
        }
        line.click(ss.Delegate.create(this, function() {
            $('li', this.element).removeClass('Selected');
            line.addClass('Selected');
            if (this._emailProfile != null && this._emailBubbles != null) {
                var awx = new Await();
                awx.addFn(YesPlayLove.Clusters.EmailProfile.setOther, item.fromId).addFn(ss.Delegate.create(this._emailProfile, this._emailProfile.fillFromIdAsync), item.fromId).addAw(ss.Delegate.create(this, this.scrollToAw), this._emailProfile.element).addFn(ss.Delegate.create(this._emailBubbles, this._emailBubbles.showBubbles), item.fromId);
                if (item.unread && item.lastId !== EmailBase.data.get_my().id) {
                    item.unread = false;
                    awx.addAw(ss.Delegate.create(EmailBase.data, EmailBase.data.updateStorageListsAw), EmailBase.data.get_my().id, item.fromId, item);
                }
                awx.addAw(ss.Delegate.create(this, this.refreshAw));
                awx.commit();
            }
        }));
        return line;
    }
}


////////////////////////////////////////////////////////////////////////////////
// EmailMessage

EmailMessage = function EmailMessage(cluster) {
    /// <param name="cluster" type="EmailCluster">
    /// </param>
    /// <field name="_header$5" type="jQueryObject">
    /// </field>
    /// <field name="_messageBody$5" type="jQueryObject">
    /// </field>
    EmailMessage.initializeBase(this, [ cluster ]);
}
EmailMessage.prototype = {
    _header$5: null,
    _messageBody$5: null,
    
    build: function EmailMessage$build(active) {
        /// <param name="active" type="Boolean">
        /// </param>
        /// <returns type="EmailBase"></returns>
        this.initialize(active);
        this.element.addClass('Section LeftSide Message').hide().unbind('keyup.EmailMessage').bind('keyup.EmailMessage', function(e) {
            DomElement.cancelEvent(e);
        });
        if (active) {
            this._header$5 = $("<div class='Header'/>").appendTo(this.element).html(EmailTheme.messageTitle);
            $("<span class='ActionBtn ReplyBtn'/>").appendTo(this._header$5).html(EmailTheme.replyButton).click(ss.Delegate.create(this, function() {
                new Await().addAw(ss.Delegate.create(this, this.rebuildAw), false).addDl(ss.Delegate.create(this, function(aw) {
                    if (this._emailBubbles != null) {
                        var inputEl = this._emailBubbles.appendReply(true).fill('').focusInput().element;
                        this.scrollInViewAw(aw, inputEl);
                    }
                    else {
                        aw.done();
                    }
                })).commit();
            }));
        }
        this._messageBody$5 = $("<p class='Body MessageBody'/>").appendTo(this.element);
        return this;
    },
    
    rebuildAw: function EmailMessage$rebuildAw(awp, active) {
        /// <param name="awp" type="Await">
        /// </param>
        /// <param name="active" type="Boolean">
        /// </param>
        var msg = this._messageBody$5.html();
        new Await().addAw(ss.Delegate.create(this, this.fadeOutAw), ThemeBase.fadeOut).addDx(ss.Delegate.create(this, function() {
            this.build(active).fill(msg);
        })).addAw(ss.Delegate.create(this, this.fadeInAw), ThemeBase.fadeIn).commit(awp);
    },
    
    fill: function EmailMessage$fill(msg) {
        /// <param name="msg" type="Object">
        /// </param>
        /// <returns type="EmailBase"></returns>
        this._messageBody$5.html(msg);
        return this;
    }
}


////////////////////////////////////////////////////////////////////////////////
// YesPlayLove.Clusters.EmailProfile

YesPlayLove.Clusters.EmailProfile = function YesPlayLove_Clusters_EmailProfile(cluster) {
    /// <param name="cluster" type="EmailCluster">
    /// </param>
    /// <field name="_jar$5" type="jQueryObject">
    /// </field>
    /// <field name="_photo$5" type="jQueryObject">
    /// </field>
    /// <field name="_image$5" type="jQueryObject">
    /// </field>
    /// <field name="_info$5" type="jQueryObject">
    /// </field>
    /// <field name="_name$5" type="jQueryObject">
    /// </field>
    /// <field name="_bio$5" type="jQueryObject">
    /// </field>
    /// <field name="otherPersonId" type="String" static="true">
    /// </field>
    YesPlayLove.Clusters.EmailProfile.initializeBase(this, [ cluster ]);
}
YesPlayLove.Clusters.EmailProfile.setOther = function YesPlayLove_Clusters_EmailProfile$setOther(id) {
    /// <param name="id" type="String">
    /// </param>
    YesPlayLove.Clusters.EmailProfile.otherPersonId = id;
}
YesPlayLove.Clusters.EmailProfile.prototype = {
    _jar$5: null,
    _photo$5: null,
    _image$5: null,
    _info$5: null,
    _name$5: null,
    _bio$5: null,
    
    build: function YesPlayLove_Clusters_EmailProfile$build(active) {
        /// <param name="active" type="Boolean">
        /// </param>
        /// <returns type="EmailBase"></returns>
        this.initialize(active);
        this.element.addClass('Section');
        this._jar$5 = $("<div class='Jar'/>").appendTo(this.element).hide();
        this._photo$5 = $("<div class='PhotoCell'/>").appendTo(this._jar$5);
        this._image$5 = $('<img/>').appendTo(this._photo$5).css({ width: '100%' });
        this._info$5 = $("<div class='InfoCell'/>").appendTo(this._jar$5);
        this._name$5 = $("<p class='Name Info'/>").appendTo(this._info$5);
        this._bio$5 = $("<p class='Bio Info'/>").appendTo(this._info$5);
        return this;
    },
    
    fillFromIdAsync: function YesPlayLove_Clusters_EmailProfile$fillFromIdAsync(userId) {
        /// <param name="userId" type="String">
        /// </param>
        this._photo$5.hide();
        new Await().addFn(ss.Delegate.create(this, this.hideJar)).addAw(ProfileData.getUserByIdAw, userId).addDx(ss.Delegate.create(this, function(aw) {
            var user = aw.get_item(PkgBase.resultRx);
            if (ss.isValue(user)) {
                this.fill(user);
            }
        })).addAw(ss.Delegate.create(this, this.slideDownAw), ThemeBase.slideDown).addDx(ss.Delegate.create(this, function() {
            this._photo$5.fadeIn(250);
        })).addFn(ss.Delegate.create(this._emailBubbles, this._emailBubbles.scrollActiveToView)).commit();
    },
    
    fill: function YesPlayLove_Clusters_EmailProfile$fill(user) {
        /// <param name="user" type="Object">
        /// </param>
        /// <returns type="EmailBase"></returns>
        var u = user;
        this._image$5.attr('src', u.photo);
        this._name$5.html(u.name);
        this._bio$5.html(u.bio);
        return this;
    }
}


////////////////////////////////////////////////////////////////////////////////
// EmailReply

EmailReply = function EmailReply(cluster) {
    /// <param name="cluster" type="EmailCluster">
    /// </param>
    /// <field name="_header$5" type="jQueryObject">
    /// </field>
    /// <field name="_replyBody$5" type="jQueryObject">
    /// </field>
    /// <field name="_sendAction$5" type="Function">
    /// </field>
    /// <field name="_cancelAction$5" type="Function">
    /// </field>
    /// <field name="_title$5" type="String">
    /// </field>
    /// <field name="_hasEvents$5" type="Boolean" static="true">
    /// </field>
    this._title$5 = EmailTheme.replyTitle;
    EmailReply.initializeBase(this, [ cluster ]);
}
EmailReply._attachEvents$5 = function EmailReply$_attachEvents$5() {
    /// <returns type="Boolean"></returns>
    $('.EmailBubble .Reply textarea').live('keypress.emailreply', function(e) {
        if (e.which === 13 && e.shiftKey) {
            $('.EmailBubble .Reply .SendBtn').click();
        }
    });
    return true;
}
EmailReply.sendPopupAw = function EmailReply$sendPopupAw(awp, usr, e) {
    /// <param name="awp" type="Await">
    /// </param>
    /// <param name="usr" type="YoshiUser">
    /// </param>
    /// <param name="e" type="jQueryEvent">
    /// </param>
    var trigger = $(e.target);
    YesPlayLove.Clusters.EmailProfile.setOther(usr.id);
    var emm = new EmailReply(null).fromHtml('<div/>');
    emm.wrapper = $("<div class='EmailBubble PopUp' style='position:absolute'/>").appendTo('#PageContent').css('top', trigger.offset().top + trigger.height() - $('#PageContent').offset().top + 'px');
    emm._cancelAction$5 = function() {
        emm.wrapper.remove();
        emm.hiderAw(Await.get_asyncAw(), false, 0);
        emm.escapeKeyAction();
    };
    emm._sendAction$5 = emm._cancelAction$5;
    emm._title$5 = EmailTheme.messageTitle;
    emm.build(true).appendTo(emm.wrapper).fadeInAw(Await.get_asyncAw());
    emm.focusInput();
    emm.hiderAw(Await.get_asyncAw(), true, 0.65);
    emm.escapeKeyAction(emm._cancelAction$5);
    awp.done();
}
EmailReply.prototype = {
    _header$5: null,
    _replyBody$5: null,
    _sendAction$5: null,
    _cancelAction$5: null,
    
    build: function EmailReply$build(active) {
        /// <param name="active" type="Boolean">
        /// </param>
        /// <returns type="EmailBase"></returns>
        this.initialize(active);
        this.element.hide().empty().addClass('Section RightSide Reply').removeClass('RightSideInput').unbind('keyup.EmailReply').bind('keyup.EmailReply', function(e) {
            DomElement.cancelEvent(e);
        });
        if (active) {
            this.element.addClass('RightSideInput');
            this._header$5 = $("<div class='Header'/>").appendTo(this.element).html(this._title$5);
            this._replyBody$5 = $("<textarea class='Body ReplyBody'/>").appendTo(this.element);
            $("<span class='ActionBtn CancelBtn'/>").appendTo(this._header$5).html(EmailTheme.cancelButton).click(this._cancelAction$5);
            $("<span class='ActionBtn SendBtn'/>").appendTo(this._header$5).html(EmailTheme.sendButton).click(ss.Delegate.create(this, function(e) {
                if (String.isNullOrEmpty(this._replyBody$5.getFValueString())) {
                    new Ask().okAw(Await.get_asyncAw(), String.format(EmailTheme.pleaseFillMsg, this._title$5.toLowerCase()));
                }
                else {
                    if (this._emailBubbles != null) {
                        this._emailBubbles.rebuildMessage(false).appendReply(true).focusInput();
                    }
                    this.rebuild(false);
                    var awx = new Await();
                    awx.addAw(ss.Delegate.create(EmailBase.data, EmailBase.data.sendMailAw), YesPlayLove.Clusters.EmailProfile.otherPersonId, this._replyBody$5.getFValueString());
                    if (this._emailInbox != null) {
                        awx.addAw(ss.Delegate.create(this._emailInbox, this._emailInbox.refreshAw));
                    }
                    awx.addDx(ss.Delegate.create(this, function() {
                        if (this._sendAction$5 != null) {
                            this._sendAction$5(e);
                        }
                    })).commit();
                }
            }));
        }
        else {
            this._replyBody$5 = $("<p class='Body ReplyBody'/>").appendTo(this.element);
        }
        return this;
    },
    
    rebuild: function EmailReply$rebuild(active) {
        /// <param name="active" type="Boolean">
        /// </param>
        /// <returns type="EmailReply"></returns>
        var msg = (this._active) ? this._replyBody$5.val() : this._replyBody$5.html();
        new Await().addAw(ss.Delegate.create(this, this.fadeOutAw), ThemeBase.fadeOut).addDx(ss.Delegate.create(this, function() {
            this.build(active).fill(msg);
        })).addAw(ss.Delegate.create(this, this.fadeInAw), ThemeBase.fadeIn).commit();
        return this;
    },
    
    fill: function EmailReply$fill(msg) {
        /// <param name="msg" type="Object">
        /// </param>
        /// <returns type="EmailBase"></returns>
        this._replyBody$5.html(msg).val(msg);
        return this;
    },
    
    focusInput: function EmailReply$focusInput() {
        /// <returns type="EmailBase"></returns>
        new Await().addAw(ss.Delegate.create(this, this.slideDownAw), ThemeBase.slideDown).addFn(ss.Delegate.create(this, this.focus), this._replyBody$5).addAw(ss.Delegate.create(this, this.scrollInViewAw), this.element).commit();
        return this;
    }
}


////////////////////////////////////////////////////////////////////////////////
// FeedBubble

FeedBubble = function FeedBubble(awp, appendTo) {
    /// <param name="awp" type="Await">
    /// </param>
    /// <param name="appendTo" type="jQueryObject">
    /// </param>
    /// <field name="_feedList$3" type="Array">
    /// </field>
    FeedBubble.initializeBase(this);
    ss.Debug.assert(appendTo != null, 'appendTo != null');
    AlivenessFeed.currentFeed = this;
    new Await().addAw(ss.Delegate.create(Master.profile, Master.profile.getFeedAw)).handleDl(Exceptions.blobLoadError, Await.ignoreAw).addDx(ss.Delegate.create(this, function() {
        if (appendTo != null) {
            appendTo.empty();
        }
        this.element = $("<div class='FeedCluster'/>");
        this._feedList$3 = Master.profile.get_feedList();
        this._feedList$3.reverse();
        var $enum1 = ss.IEnumerator.getEnumerator(Master.profile.get_feedList());
        while ($enum1.moveNext()) {
            var i = $enum1.current;
            AlivenessBubble.nue(this.element, i);
        }
        this._feedList$3.reverse();
        this.element.appendTo(appendTo);
    })).commit(awp);
}
FeedBubble.newAw = function FeedBubble$newAw(awp, appendTo) {
    /// <param name="awp" type="Await">
    /// </param>
    /// <param name="appendTo" type="jQueryObject">
    /// </param>
    new FeedBubble(awp, appendTo);
}
FeedBubble.prototype = {
    _feedList$3: null,
    
    refresh: function FeedBubble$refresh() {
        FeedBubble.newAw(Await.get_asyncAw(), this.element.parent());
    }
}


////////////////////////////////////////////////////////////////////////////////
// MagBubble

MagBubble = function MagBubble(awp) {
    /// <param name="awp" type="Await">
    /// </param>
    /// <field name="_monitorInterval$2" type="Number" integer="true" static="true">
    /// </field>
    /// <field name="_classCount$2" type="Number" integer="true" static="true">
    /// </field>
    /// <field name="_awp$2" type="Await">
    /// </field>
    /// <field name="_data$2" type="MagneticData">
    /// </field>
    /// <field name="_className$2" type="String">
    /// </field>
    /// <field name="_itemIndex$2" type="Number" integer="true">
    /// </field>
    /// <field name="_listItems$2" type="jQueryObject">
    /// </field>
    /// <field name="_listTitle$2" type="String">
    /// </field>
    /// <field name="_magList$2" type="jQueryObject">
    /// </field>
    /// <field name="_magName$2" type="jQueryObject">
    /// </field>
    /// <field name="_eyes$2" type="Eyes">
    /// </field>
    /// <field name="_timer$2" type="Number" integer="true" static="true">
    /// </field>
    this._listTitle$2 = MagneticListTheme.bubbleTopic;
    MagBubble.initializeBase(this);
    this.ClassName = 'MagBubble' + (++MagBubble._classCount$2);
    this._awp$2 = awp;
    this._data$2 = new MagneticData();
    this._eyes$2 = new Eyes().flirting(true);
    this._eyes$2.element.appendTo(document.body);
    this._build$2();
}
MagBubble.prototype = {
    _awp$2: null,
    _data$2: null,
    _className$2: null,
    _itemIndex$2: 0,
    _listItems$2: null,
    _magList$2: null,
    _magName$2: null,
    _eyes$2: null,
    
    get_listTitle: function MagBubble$get_listTitle() {
        /// <value type="String"></value>
        return this._listTitle$2;
    },
    set_listTitle: function MagBubble$set_listTitle(value) {
        /// <value type="String"></value>
        this._listTitle$2 = value;
        return value;
    },
    
    get__hasAnyItem$2: function MagBubble$get__hasAnyItem$2() {
        /// <value type="Boolean"></value>
        if (this._itemIndex$2 > 1) {
            return true;
        }
        var items = $('.MagItem');
        return items.length > 0 && !String.isNullOrEmpty(items.val().trim());
    },
    
    _build$2: function MagBubble$_build$2() {
        this._className$2 = this.ClassName + '_Element';
        this.element = $('<div/>').addClass(this._className$2);
        $(String.format('.{0} .MagName, .{0} .MagItem', this._className$2)).live('keypress.maglist', ss.Delegate.create(this, function(e) {
            this._data$2.saved(false);
            if (e.which === 9 || e.which === 13) {
                DomElement.cancelEvent(e);
                if (!$(e.target).is('.MagName')) {
                    this._saveRecord$2();
                }
                this._addDropGadget$2();
                this._addListButtons$2();
                this._addLastLine$2();
            }
            this._data$2.updatePage();
        })).live('focus.maglist', ss.Delegate.create(this, function(e) {
            Master.page.focusEvent(e);
            this._eyes$2.moveToElement($(e.target));
        })).live('blur.maglist', ss.Delegate.create(this, function(e) {
            Master.page.focusEvent(null);
            this._eyes$2.followMouse();
            var el = $(e.target);
            if (el[0].tagName.toLowerCase() === 'textarea') {
                el.vertHtml();
            }
        }));
        $(String.format('.{0} .MagName', this._className$2)).live('blur.magname', ss.Delegate.create(this, function(e) {
            var target = $(e.target);
            Inform.trace('Bluring {0}[{1}]', e.target.tagName, e.target.tabIndex);
            Master.page.focusEvent(null);
            this._eyes$2.followMouse();
            var xname = DomElement.cleanName(target.getFValueString());
            var magName = xname.toLowerCase();
            var recName = DomElement.cleanName(this._data$2.get_recordName()).toLowerCase();
            if (!String.isNullOrEmpty(magName) && magName !== recName) {
                if (Object.keyExists(this._data$2.records, magName)) {
                    new Await().addFn(ss.Delegate.create(this, this._putNewList$2), xname).commit();
                }
                else if (!String.isNullOrEmpty(magName)) {
                    new Await().addDx(ss.Delegate.create(this, function() {
                        this._listItems$2.empty();
                        this._itemIndex$2 = 0;
                    })).addFn(ss.Delegate.create(this, this._addDropGadget$2)).addFn(ss.Delegate.create(this, this._addLastLine$2)).addFn(ss.Delegate.create(this, this._addListButtons$2)).commit();
                }
            }
        }));
        new Await().addAw(ss.Delegate.create(this._data$2, this._data$2.loadRecordsAw)).addFn(ss.Delegate.create(this, this._startNewList$2)).addDx(ss.Delegate.create(this, function() {
            window.clearInterval(MagBubble._timer$2);
            MagBubble._timer$2 = window.setInterval(ss.Delegate.create(this, function() {
                this._monitorLoop$2();
            }), 7000);
        })).commit(this._awp$2);
    },
    
    destroy: function MagBubble$destroy() {
        window.clearInterval(MagBubble._timer$2);
        MagBubble._timer$2 = 0;
        $(String.format('.{0} .MagName, .{0} .MagItem', this._className$2)).die('keydown.maglist').die('focus.maglist').die('blur.maglist');
        $(String.format('.{0} .MagName', this._className$2)).die('blur.magname');
        this._eyes$2.destroy();
    },
    
    _putNewList$2: function MagBubble$_putNewList$2(name) {
        /// <param name="name" type="String">
        /// </param>
        new Await().addFn(ss.Delegate.create(this._data$2, this._data$2.loadRecord), name).handleDl(Exceptions.blobLoadError, Await.ignoreAw).addFn(ss.Delegate.create(this, this._createListHead$2)).addFn(ss.Delegate.create(this, this._createNodes$2)).addFn(ss.Delegate.create(this, this._replaceList$2)).addFn(ss.Delegate.create(this, this._addLastLine$2)).addFn(ss.Delegate.create(this, this._addListButtons$2)).addFn(ss.Delegate.create(this._data$2, this._data$2.updatePage)).commit();
    },
    
    _startNewList$2: function MagBubble$_startNewList$2() {
        Inform.trace('StartNewList()');
        new Await().addFn(ss.Delegate.create(this._data$2, this._data$2.emptyRecord)).addFn(ss.Delegate.create(this, this._createListHead$2)).addFn(ss.Delegate.create(this, this._replaceList$2)).addFn(ss.Delegate.create(this, this._addListButtons$2)).addDx(ss.Delegate.create(this, function() {
            this._magName$2.val('').focus();
        })).addAw(ss.Delegate.create(this, this.scrollInViewAw), this._magName$2).commit();
    },
    
    _addLastLine$2: function MagBubble$_addLastLine$2() {
        var item = $('.MagItem', this.element).last();
        if (!item.length || !String.isNullOrEmpty(item.val().trim())) {
            this.scrollInViewAw(Await.get_asyncAw(), this._addItem$2().focus());
        }
        else {
            this.scrollInViewAw(Await.get_asyncAw(), item.focus());
        }
    },
    
    _replaceList$2: function MagBubble$_replaceList$2() {
        Inform.trace('ReplaceList()');
        this.element.empty().append(this._magList$2);
        this._addDropGadget$2();
    },
    
    _createListHead$2: function MagBubble$_createListHead$2() {
        this._itemIndex$2 = 0;
        this._magName$2 = $("<input class='MagName' type='text' tabindex='1'/>");
        this._listItems$2 = $("<ol id='MagList'/>");
        this._magList$2 = $("<div id='MagneticList' class='MagneticList'/>").append(this._magName$2).append(this._listItems$2);
        if (ss.isValue(this._data$2.get_dataRecord())) {
            Inform.trace('-- Putting existing record');
            this._magList$2.prepend($("<div class='MagTitle'/>").html(this._listTitle$2));
            this._magName$2.fValueString(this._data$2.get_recordName());
        }
        else {
            Inform.trace('-- Putting new record');
            this._magList$2.prepend($("<div class='MagTitle'/>").html('New - ' + this._listTitle$2));
        }
    },
    
    _createNodes$2: function MagBubble$_createNodes$2() {
        this._itemIndex$2 = 0;
        if (ss.isNullOrUndefined(this._data$2.get_recordName())) {
            return;
        }
        var $enum1 = ss.IEnumerator.getEnumerator(this._data$2.get_dataRecord().items);
        while ($enum1.moveNext()) {
            var item = $enum1.current;
            if (item.trim().length > 0) {
                var i = this._addItem$2();
                i.fValueString(item);
            }
        }
    },
    
    _addItem$2: function MagBubble$_addItem$2() {
        /// <returns type="jQueryObject"></returns>
        var item = $('<li/>');
        var input = $("<textarea class='MagItem'/>").appendTo(item).attr('tabindex', (this._itemIndex$2 + 2).toString());
        $("<span class='MagItemDelete'/>").appendTo(item).html('x').click(ss.Delegate.create(this, function() {
            item.remove();
            this._saveRecord$2();
        })).attr('title', MagneticListTheme.deleteItemTitle);
        this._listItems$2.append(item);
        this._itemIndex$2++;
        return input;
    },
    
    _addListButtons$2: function MagBubble$_addListButtons$2() {
        $('.MagDelete').remove();
        $('.MagNew').remove();
        if (this.get__hasAnyItem$2()) {
            $("<span class='MagDelete'/>").insertBefore(this._listItems$2).html('delete').attr('title', MagneticListTheme.deleteListTitle).click(ss.Delegate.create(this, function() {
                new Await().addAw(ss.Delegate.create(new Ask(), new Ask().okCancelAw), { Message: String.format('Delete {0} for sure?', this._data$2.get_recordName()), Title: '', OkFace: 'Oh Yea!' }).addAw(DomElement.requireResultAw, true).addFn(ss.Delegate.create(this._data$2, this._data$2.updatePage)).addFn(ss.Delegate.create(this._data$2, this._data$2.deleteList), this._data$2.get_recordName()).addFn(ss.Delegate.create(this, this._startNewList$2)).commit();
            }));
        }
        if (Object.getKeyCount(this._data$2.records) > 0 && !String.isNullOrEmpty(this._magName$2.val().trim())) {
            $("<span class='MagNew'/>").insertBefore(this._listItems$2).html('new').attr('title', MagneticListTheme.newListTitle).click(ss.Delegate.create(this, function() {
                new Await().addFn(ss.Delegate.create(this, this._saveRecord$2)).addFn(ss.Delegate.create(this._data$2, this._data$2.emptyRecord)).addFn(ss.Delegate.create(this, this._startNewList$2)).commit();
            }));
        }
    },
    
    _saveRecord$2: function MagBubble$_saveRecord$2() {
        if (this.get__hasAnyItem$2()) {
            this._data$2.saveRecord();
        }
    },
    
    _addDropGadget$2: function MagBubble$_addDropGadget$2() {
        new Await().addDx(ss.Delegate.create(this, function() {
            var names = this._data$2.nameList();
            if (Object.getKeyCount(names) > 0) {
                new EyeFocusDropMenu(this._magName$2, names, ss.Delegate.create(this, function(ee, postName) {
                    new Await().addFn(ss.Delegate.create(this, this._saveRecord$2)).addFn(ss.Delegate.create(this, this._putNewList$2), postName).commit();
                }), this._eyes$2);
            }
        })).commit();
    },
    
    _monitorLoop$2: function MagBubble$_monitorLoop$2() {
        Inform.trace('MonitorLoop');
        if (!Master.page.isFocused($('.MagName', this.element))) {
            if (!this._data$2.saved()) {
                this._saveRecord$2();
            }
            else {
                this._data$2.updatePage();
            }
        }
    }
}


////////////////////////////////////////////////////////////////////////////////
// ProfileBase

ProfileBase = function ProfileBase(cluster) {
    /// <param name="cluster" type="ProfileCluster">
    /// </param>
    /// <field name="_profileCluster" type="ProfileCluster">
    /// </field>
    ProfileBase.initializeBase(this);
    this._profileCluster = cluster;
}
ProfileBase.prototype = {
    _profileCluster: null,
    
    get_data: function ProfileBase$get_data() {
        /// <value type="ProfileData"></value>
        return Master.profile;
    },
    
    initialize: function ProfileBase$initialize() {
        ss.Debug.assert(this.element != null, 'Element != null');
        this.element.empty();
    }
}


////////////////////////////////////////////////////////////////////////////////
// ProfileCluster

ProfileCluster = function ProfileCluster(cluster) {
    /// <param name="cluster" type="ProfileCluster">
    /// </param>
    /// <field name="_monitorInterval$6" type="Number" integer="true" static="true">
    /// </field>
    /// <field name="_timer$6" type="Number" integer="true" static="true">
    /// </field>
    /// <field name="_eyes$6" type="Eyes">
    /// </field>
    /// <field name="_alias$6" type="Nsb.Classes.Truple">
    /// </field>
    /// <field name="_birthday$6" type="Nsb.Classes.Truple">
    /// </field>
    /// <field name="_email$6" type="Nsb.Classes.Truple">
    /// </field>
    /// <field name="_height$6" type="Nsb.Classes.Truple">
    /// </field>
    /// <field name="_name$6" type="Nsb.Classes.Truple">
    /// </field>
    /// <field name="_physique$6" type="Nsb.Classes.Truple">
    /// </field>
    /// <field name="_slideShow$6" type="Actor">
    /// </field>
    /// <field name="_smoke$6" type="Nsb.Classes.Truple">
    /// </field>
    /// <field name="_emmMessage$6" type="Nsb.Classes.Truple">
    /// </field>
    /// <field name="_emmComment$6" type="Nsb.Classes.Truple">
    /// </field>
    /// <field name="_emmLike$6" type="Nsb.Classes.Truple">
    /// </field>
    /// <field name="_bio$6" type="Nsb.Classes.Truple">
    /// </field>
    ProfileCluster.initializeBase(this, [ cluster ]);
    this._profileCluster = this;
    this._eyes$6 = Eyes.bodyEyes();
}
ProfileCluster.prototype = {
    _eyes$6: null,
    _alias$6: null,
    _birthday$6: null,
    _email$6: null,
    _height$6: null,
    _name$6: null,
    _physique$6: null,
    _slideShow$6: null,
    _smoke$6: null,
    _emmMessage$6: null,
    _emmComment$6: null,
    _emmLike$6: null,
    _bio$6: null,
    
    build: function ProfileCluster$build() {
        /// <returns type="ProfileBase"></returns>
        this.element = $("<div class='ProfileCluster TrupleCluster'/>");
        this.initialize();
        this._alias$6 = this.playAlias();
        this._name$6 = this.input('name').subHtml('.Label', 'Your Name');
        this._email$6 = this.input('email').subHtml('.Label', 'Email (hidden to others)');
        this._birthday$6 = this.input('birthday').subHtml('.Label', 'Birth date m/d/y');
        this._physique$6 = this.selectBox('physique').subHtml('.Label', 'Physical appearance').subOptions('select', { none: UserTheme.leaveBlank, petite: 'Petite', slim: 'Slim', athletic: 'Athletic', average: 'Average', curvy: 'Curvy', handfull: 'A hand full' });
        this._height$6 = this.selectBox('height').subHtml('.Label', 'Height').subOptions('select', $.extend({ none: UserTheme.leaveBlank }, this._genHeightList$6()));
        this._smoke$6 = this.selectBox('smoker').subHtml('.Label', 'Do you smoke?').subOptions('select', { never: 'No', occasionally: 'Occasionally', yes: 'Yes' });
        this._emmMessage$6 = this.checkbox('emmMessage').subHtml('.Label', 'Email me when I receive a message');
        this._emmComment$6 = this.checkbox('emmComment').subHtml('.Label', 'Email me when I receive a comment');
        this._emmLike$6 = this.checkbox('emmLike').subHtml('.Label', 'Email me when I receive a like');
        this._bio$6 = this.textarea('bio').subHtml('.Label', 'About you');
        this._slideShow$6 = this.viewit('https://docs.google.com/present/embed?id=dcxgm95h_820gm7svsdq&autoStart=true&loop=true&interval=7').addClass('SlideShow').appendTo('.PageCluster');
        this._slideShow$6.element.rotate(7);
        new Await().addAw(Nsb.Classes.Truple.fillDataFromAw, this.get_data().get_my()).addFn(ss.Delegate.create(this, this._attachEvents$6)).addAw(ss.Delegate.create(this, this._slideEmInAw$6)).commit();
        return this;
    },
    
    _save$6: function ProfileCluster$_save$6(e) {
        /// <param name="e" type="jQueryEvent">
        /// </param>
        Nsb.Classes.Truple.scoopDataTo(this.get_data().get_my());
        this.get_data().saveMyProfileAsync(Await.get_asyncAw(), PkgBase.resultRx);
    },
    
    destroy: function ProfileCluster$destroy() {
        window.clearInterval(ProfileCluster._timer$6);
        ProfileCluster._timer$6 = 0;
        this._eyes$6.destroy();
    },
    
    _monitorLoop$6: function ProfileCluster$_monitorLoop$6() {
        this.get_data().updatePage();
        if (!this.get_data().saved()) {
            this._save$6();
        }
    },
    
    _slideEmInAw$6: function ProfileCluster$_slideEmInAw$6(awp) {
        /// <param name="awp" type="Await">
        /// </param>
        var ani = new Await();
        ani.sleep(500);
        this.addSlideTruples(ani);
        ani.sleep(100);
        ani.addDl(ss.Delegate.create(this, function() {
            var p = this._slideShow$6.element.position();
            this._slideShow$6.element.css({ top: 0, left: 0 });
            this._slideShow$6.element.css('visibility', 'visible').animate({ top: p.top, left: p.left }, 400, 'swing', function() {
                ani.done();
            });
        }));
        ani.addDx(ss.Delegate.create(this, function() {
            $('.Input', this._alias$6.element).focus();
        }));
        ani.addDx(ss.Delegate.create(this, function() {
            window.clearInterval(ProfileCluster._timer$6);
            ProfileCluster._timer$6 = window.setInterval(ss.Delegate.create(this, this._monitorLoop$6), 7000);
            this._monitorLoop$6();
        }));
        ani.commit(awp);
    },
    
    _genHeightList$6: function ProfileCluster$_genHeightList$6() {
        /// <returns type="Object"></returns>
        var d = {};
        for (var i = 3; i < 8; i++) {
            for (var j = 1; j < 12; j++) {
                d[i + '.' + j] = String.format('{0} {2} {1} {3}', i, j, Local.foot, ((j === 1) ? Local.inch : Local.inches));
            }
        }
        return d;
    },
    
    _attachEvents$6: function ProfileCluster$_attachEvents$6() {
        $('.Truple .Input').live('blur.truple', ss.Delegate.create(this, this._save$6)).bind('change.truple', ss.Delegate.create(this, function() {
            this.get_data().saved(false);
        })).live('keydown.truple', ss.Delegate.create(this, function(e) {
            if (Keys.changeKey(e)) {
                this.get_data().saved(false);
            }
        }));
        this._trackFocus$6(true);
    },
    
    _trackFocus$6: function ProfileCluster$_trackFocus$6(eyes) {
        /// <param name="eyes" type="Boolean">
        /// </param>
        $('.Truple .Input').live('focus.trupleInput', function(e) {
            Master.page.focusEvent(e);
            $(e.target).addClass('Focused');
            try {
                DomElement.getTruple(e.target).element.removeClass('Focused');
            }
            catch ($e1) {
            }
        }).live('blur.trupleInput', function(e) {
            Master.page.focusEvent(e);
            $(e.target).removeClass('Focused');
            try {
                DomElement.getTruple(e.target).element.removeClass('Focused');
            }
            catch ($e1) {
            }
        });
        if (eyes) {
            $('.Truple').live('focus.truple', ss.Delegate.create(this, function(e) {
                this._eyes$6.moveToElement($(e.target));
            }));
        }
    }
}


////////////////////////////////////////////////////////////////////////////////
// SearchCluster

SearchCluster = function SearchCluster(awp, insertAfter) {
    /// <param name="awp" type="Await">
    /// </param>
    /// <param name="insertAfter" type="jQueryObject">
    /// </param>
    /// <field name="_searchBtn$4" type="Nsb.Classes.Truple">
    /// </field>
    SearchCluster.initializeBase(this);
    this.element = $("<div class='SearchCluster TrupleCluster'/>");
    var female = this.checkbox('Female').subHtml('span', 'Female?').subAttr('input', 'checked', 'checked');
    this._searchBtn$4 = this.button('Search').subValue('button', 'Search');
    if (ss.isValue(insertAfter)) {
        this.element.insertAfter(insertAfter);
    }
    new Await().addAw(ss.Delegate.create(this, this._slideEmInAw$4)).commit(awp);
}
SearchCluster.aw = function SearchCluster$aw(awp, insertAfter) {
    /// <param name="awp" type="Await">
    /// </param>
    /// <param name="insertAfter" type="jQueryObject">
    /// </param>
    awp.done();
}
SearchCluster.prototype = {
    _searchBtn$4: null,
    
    refresh: function SearchCluster$refresh() {
        new Await().addAw(SearchCluster.aw, this.element).addDx(ss.Delegate.create(this, function() {
            this.element.remove();
        })).commit();
    },
    
    _slideEmInAw$4: function SearchCluster$_slideEmInAw$4(awp) {
        /// <param name="awp" type="Await">
        /// </param>
        var ani = new Await();
        ani.sleep(500);
        this.addSlideTruples(ani);
        ani.sleep(100);
        ani.addDx(ss.Delegate.create(this, function() {
            $('button', this._searchBtn$4.element).focus();
        }));
        ani.commit(awp);
    }
}


////////////////////////////////////////////////////////////////////////////////
// TopBar

TopBar = function TopBar(element, options) {
    /// <param name="element" type="jQueryObject">
    /// </param>
    /// <param name="options" type="Object">
    /// </param>
    /// <field name="instance" type="TopBar" static="true">
    /// </field>
    /// <field name="_options$2" type="Object">
    /// </field>
    /// <field name="_barEl$2" type="jQueryObject">
    /// </field>
    /// <field name="_linksHidden$2" type="Boolean">
    /// </field>
    /// <field name="_gigShow$2" type="GigShowEdit" static="true">
    /// </field>
    TopBar.initializeBase(this);
    TopBar.instance = this;
    this.element = element;
    this._options$2 = options || { links: true };
    this._build$2();
}
TopBar.newLink = function TopBar$newLink(face, page) {
    /// <param name="face" type="String">
    /// </param>
    /// <param name="page" type="String">
    /// </param>
    /// <returns type="jQueryObject"></returns>
    var lnk = $('<a/>').attr('href', 'javascript:;').html(face).swallowClick(function() {
        Master.GoPage(page);
    });
    if (Type.getType(page) === Type.getInstanceType(Master.page)) {
        lnk.addClass('CurrentPage');
    }
    return lnk;
}
TopBar.prototype = {
    _options$2: null,
    _barEl$2: null,
    _linksHidden$2: false,
    
    _build$2: function TopBar$_build$2() {
        this._barEl$2 = $("<div id='TopBar' class='AboveContent'/>").prependTo(this.element);
        if (this._options$2['links']) {
            TopBar.newLink(TopBarTheme.homeBtnText, AllPages.homePage).appendTo(this._barEl$2).addClass('BarLink');
            TopBar.newLink(TopBarTheme.magneticListBtnText, AllPages.magneticListPage).appendTo(this._barEl$2).addClass('BarLink');
            TopBar.newLink(TopBarTheme.searchBtnText, AllPages.searchPage).appendTo(this._barEl$2).addClass('BarLink');
            TopBar.newLink(TopBarTheme.emailBtnText, AllPages.emailPage).appendTo(this._barEl$2).addClass('BarLink');
            TopBar.newLink(TopBarTheme.gamesBtnText, AllPages.gamesPage).appendTo(this._barEl$2).addClass('BarLink');
            TopBar.newLink(TopBarTheme.featuresBtnText, AllPages.featuresPage).appendTo(this._barEl$2).addClass('BarLink');
            var gotGear = [];
            gotGear.add(AllPages.homePage);
            gotGear.add(AllPages.magneticListPage);
            gotGear.add(AllPages.searchPage);
            gotGear.add(AllPages.emailPage);
            gotGear.add(AllPages.gamesPage);
            gotGear.add(AllPages.featuresPage);
            if (gotGear.contains(ThemeBase.currentPageClass)) {
                this._addSlides$2();
            }
            $("<span id='SavedIndicator'/>").appendTo(this._barEl$2);
        }
    },
    
    _addSlides$2: function TopBar$_addSlides$2() {
        var slideControls = $("<div class='SlideControls'/>").appendTo(this._barEl$2);
        new Await().waitDx(function() {
            return Master.profile.get_myId() != null;
        }).loadText('ColorPickerTable', 'Scripts/Data/GigColorPicker.html').loadScript('Scripts/WhirliGig.debug.js', function(aw) {
            if (TopBar._gigShow$2 != null) {
                TopBar._gigShow$2.destroy();
            }
            TopBar._gigShow$2 = new GigShowEdit();
            TopBar._gigShow$2.editing = true;
            TopBar._gigShow$2.initializeAw(aw, { PartitionKey: 'db/gigs/' + ThemeBase.currentPageClass, RowKey: Master.profile.get_myId(), PageSelectTo: '#PageGigs', SlideControls: slideControls });
        }).addDl(function(aw) {
            TopBar._gigShow$2.restoreAw(aw);
        }).commit();
    },
    
    hideLinksAw: function TopBar$hideLinksAw(awp) {
        /// <param name="awp" type="Await">
        /// </param>
        this._linksHidden$2 = true;
        new Await().waitDx(ss.Delegate.create(this, function() {
            return this._barEl$2.find('.CornerUser').length > 0;
        })).addDx(ss.Delegate.create(this, function() {
            this._barEl$2.find('.CornerUser').unbind('click').removeClass('Hoverable');
            this._barEl$2.find('a').css('visibility', 'hidden');
        })).commit(awp);
    },
    
    showUser: function TopBar$showUser() {
        new Await().addDx(function() {
            $('#TopBar .CornerUser').remove();
        }).addDx(ss.Delegate.create(this, function() {
            var name = (Master.profile.get_my() != null) ? (Master.profile.get_my().alias || Master.profile.get_my().name || '') : '';
            $("<div class='CornerUser Hoverable'/>").appendTo(this._barEl$2).append($("<span class='UserName'>" + name + '</span>')).append(Master.fbUser.get_photoTag().addClass('UserPhoto AboveContent')).click(function() {
                Master.GoPage(AllPages.profilePage);
            }).rotate({ animateTo: 360, duration: 700 });
            if (!this._options$2['links']) {
                this._barEl$2.find('.CornerUser').unbind('click').removeClass('Hoverable');
            }
        })).addDx(ss.Delegate.create(this, function(aw) {
            if (this._linksHidden$2) {
                this.hideLinksAw(aw);
            }
        })).commit();
    },
    
    updatePage: function TopBar$updatePage(pu) {
        /// <param name="pu" type="PageUpdate">
        /// </param>
        $('#SavedIndicator').html((pu.saved) ? TopBarTheme.saved : TopBarTheme.unsaved);
    }
}


EmotionalScale.registerClass('EmotionalScale', Actor);
AlivenessFeed.registerClass('AlivenessFeed');
EmailData.registerClass('EmailData', SavableData);
YoshiPage.registerClass('YoshiPage', ProfileTruple, IPage);
YoshiFlow.registerClass('YoshiFlow', YoshiPage);
AlivenessBubble.registerClass('AlivenessBubble', Actor);
EditBase.registerClass('EditBase', Actor);
AlivenessBubbleEdit.registerClass('AlivenessBubbleEdit', EditBase);
CommentBubble.registerClass('CommentBubble', EditBase);
EditListHtml.registerClass('EditListHtml', EditHtml);
EmailBase.registerClass('EmailBase', Nsb.Classes.Truple);
EmailBubbles.registerClass('EmailBubbles', EmailBase);
EmailCluster.registerClass('EmailCluster', EmailBase);
EmailInbox.registerClass('EmailInbox', EmailBase);
EmailMessage.registerClass('EmailMessage', EmailBase);
YesPlayLove.Clusters.EmailProfile.registerClass('YesPlayLove.Clusters.EmailProfile', EmailBase);
EmailReply.registerClass('EmailReply', EmailBase);
FeedBubble.registerClass('FeedBubble', Actor);
MagBubble.registerClass('MagBubble', Cluster);
ProfileBase.registerClass('ProfileBase', ProfileTruple);
ProfileCluster.registerClass('ProfileCluster', ProfileBase);
SearchCluster.registerClass('SearchCluster', Nsb.Classes.Truple);
TopBar.registerClass('TopBar', Cluster);
AlivenessFeed.currentFeed = null;
EmailData.sentRx = 'sent';
EmailData.rcvdRx = 'rcvd';
EmailBase.data = null;
EmailCluster._timer$5 = 0;
EmailCluster.monitorInbox = true;
YesPlayLove.Clusters.EmailProfile.otherPersonId = null;
EmailReply._hasEvents$5 = EmailReply._attachEvents$5();
MagBubble._classCount$2 = 0;
MagBubble._timer$2 = 0;
ProfileCluster._timer$6 = 0;
TopBar.instance = null;
TopBar._gigShow$2 = null;
})();

//! This script was generated using Script# v0.7.4.0
